/**
 * 项目名：phms3
 * 日期：    2019-11-22 16:35:44
 * Copyright (c) 2015- HTSC-版权所有
 */

package com.joysuch.wwyt.core.repository;

import java.util.List;

import com.joysuch.wwyt.core.entity.BaseRoleMenuFunction;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

/**
 * BaseBizCodeSeedDao
 *
 */
public interface BaseRoleMenuFunctionDao extends JpaRepository<BaseRoleMenuFunction, Long> {
    public Page<BaseRoleMenuFunction> findAll(Specification<BaseRoleMenuFunction> spec, Pageable pageable);

    public BaseRoleMenuFunction save(BaseRoleMenuFunction bean);

    public void delete(BaseRoleMenuFunction bean);

    @Modifying
    @Transactional
    @Query("delete from BaseRoleMenuFunction m where m.roleId=?1 and m.menuId in (?2)")
    public void deleteByIds(Long roleId, List<Long> ids);

    @Query("select distinct(m.menuId) from BaseRoleMenuFunction m where m.roleId=?1")
    public List<Long> selectMenuIdsByJobId(Long jobId);

    @Query("select distinct(m.menuId) from BaseRoleMenuFunction m where m.roleId in (?1)")
    public List<Long> selectMenuIdsByRoleIds(List<Long> roleIds);

    @Query("select distinct(f.name) from BaseRoleMenuFunction m inner join BaseMenuFunction f  on m.menuId=f.id   where  f.depth=1  and m.roleId in (?1) ")
    public List<String> selectSystemListByRoleIds(List<Long> roleIds);
}
